package com.api.shopapi.mapper;


import com.api.shopapi.entity.Cart;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
@Mapper
public interface CartMapper {

    @Insert("insert into cart" +
            "(" +
            "CartCode," +
            "UserCode," +
            "Price," +
            "GovernmentCode" +
            ")" +
            " value" +
            "(" +
            "#{cart.CartCode}," +
            "#{cart.UserCode}," +
            "#{cart.Price}," +
            "#{cart.GovernmentCode}" +
            ")")
    public int insert(@Param("cart") Cart cart);

    @Update("update cart set " +
            "Price=#{cart.Price}" +
            " where CartCode=#{cart.CartCode}")
    public int update(@Param("cart") Cart cart);

    @Delete("delete from cart where CartCode=#{cartCode}")
    public int delete(@Param("cartCode") String cartCode);

    @Select("select * from cart")
    public List<Cart> getList();

    @Select("select * from cart where CartCode=#{cartCode} limit 1")
    public Cart getByCartCode(@Param("cartCode") String cartCode);

    @Select("select * from cart where userCode=#{userCode} and businessTopCode=#{businessTopCode} limit 1")
    public Cart getByUserCodeBusinessTopCode(@Param("userCode") String userCode,
                                             @Param("businessTopCode") String businessTopCode);

    @Select("select * from cart where userCode=#{userCode} and governmentCode=#{governmentCode} limit 1")
    public Cart getByUserCodeGovernmentCode(@Param("userCode") String userCode,
                                             @Param("governmentCode") String governmentCode);



}
